<template>
  <el-dialog :visible="openRole" title="分配角色" width="500px" @close="outDia">
    <el-checkbox-group v-model="value">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{
        item.name
      }}</el-checkbox>
    </el-checkbox-group>

    <template #footer>
      <el-button @click="submit">确定</el-button>
      <el-button @click="outDia">取消</el-button>
    </template>
  </el-dialog>
</template>

<script>
import { sysRoleAPI, sysUserAPI, sysuserassignRolesAPI } from '@/api'
export default {
  props: {
    openRole: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      list: [],
      value: [],
      id: ''
    }
  },
  created() {
    this.getDate()
  },
  methods: {
    async getDate() {
      const res = await sysRoleAPI({
        page: 1,
        pagesize: 1000
      })
      console.log(res)
      this.list = res.data.rows
    },
    outDia() {
      this.$emit('update:openRole', false)
      this.value = []
    },
    async getUserInfo(id) {
      this.id = id
      const res = await sysUserAPI(id)
      console.log(res)
      this.value = res.data.roleIds
    },
    async submit() {
      await sysuserassignRolesAPI({
        roleIds: this.value,
        id: this.id
      })
      this.$message.success('修改成功')
      this.outDia()
    }
  }
}
</script>
<style></style>
